;(function (window, undefined) {
    function Loading(option) {
        this.option = option || {};
        this.ele = null;

        this.render();
    }

    Loading.prototype.render = function () {
        var html = [
            // '<div class="loading">',
            '<div>',
            '<img src="images/loading.gif">',
            '<p>' + (this.option.text || '') + '</p>', 
            '</div>',
            // '</div>'
        ];

        var ele = document.createElement('div');
        ele.classList.add('loading');
        ele.innerHTML = html.join('');
        document.body.appendChild(ele);
        this.ele = ele;
        return ele;
    }

    Loading.prototype.hide = function (params) {
        this.ele.style.display = 'none';
    }

    Loading.prototype.show = function (params) {
        this.ele.style.display = 'flex';
    }

    window.Loading = Loading;

})(window)


// 单例
var createLoading = (function () {
    var loadingComponent = null;
    return function() {
        if(!loadingComponent) {
            loadingComponent = new Loading();
        }
        return loadingComponent
    }
})()